const http = require("http");

const fs = require("fs");
const path = require("path");
http.createServer((req, res) => {
    let filePath = path.join(__dirname, "data.txt");
    //将文件所有内容读取到内存中，向前端来响应
    // let fileContent = fs.readFileSync(filePath);
    // res.end(fileContent);

    //创建文件的可读流，向res可写流写入数据
    let reader = fs.createReadStream(filePath);
    //res对象是可写流  将reader中东西写到res中
    reader.pipe(res);
}).listen(8081);

console.log("server is listening 8081")